<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');class laporan_realisasi extends My_Controller
{
	
	function __construct()
	{
		parent::__construct();
		$this->load->model('mdl_laporan_realisasi', 'laporan_realisasi');
		$this->load->library('pdf');
		$this->load->library('fungsi');
	}
	
	function index()
	{
		$this->open();
		
		# config pagination
		$config['base_url'] = base_url().'index.php/laporan_realisasi/index/';
		
		$this->pagination->initialize($config);	
		# end config pagination
		
		# get data
		//$data['results'] = $this->laporan_realisasi->getItem($config['per_page'], $this->uri->segment(3));
		
		# load view
		$this->load->view('laporan_realisasi/form_lap_realisasi_periode');
		
		$this->close();
	}
	
	
	function form_lap_realisasi_periode(){
		$this->open();
		$this->load->view('laporan_realisasi/form_lap_realisasi_periode');
		$this->close();
	}
	
	
	function view_lap_realisasi_periode(){
				$periode_awal = $this->uri->segment('3');		$periode_akhir = $this->uri->segment('4');
		
		if (($periode_awal)&&($periode_akhir)){
			$data['periode_awal']=$periode_awal;
			$data['periode_akhir']=$periode_akhir;						$ex_periode_awal=explode('-',$periode_awal);			$periode_awal_thn=$ex_periode_awal[0];			$periode_awal_bln=$ex_periode_awal[1];			$periode_awal_hari=$ex_periode_awal[2];			$datenow=date('Y-m-d');			$yearnow=date('Y');			$data['monthnow']=date('m');			//$monthlast=date("Y-m-d",strtotime("-1 month"));			$periode_awal_bln=$periode_awal_bln-1;			$date_last_month=$periode_awal_thn . '-' . $periode_awal_bln .'-'. $periode_awal_hari;					$data['monthlast']=date("m",strtotime("-1 month"));			$awal_tahun = $periode_awal_thn . '-01-01';			/*$data['periode_awal_thn']=$periode_awal_thn;			$data['periode_awal_bln']=$periode_awal_bln;			$get_data_awal_to_now = $this->laporan_realisasi->getItem_periode($awal_tahun,$periode_akhir);			$get_data_bulan_lalu = $this->laporan_realisasi->getItem_anggaran_bulan_lalu($awal_tahun,$periode_akhir);			$data['results'] = $this->laporan_realisasi->getItem_periode($awal_tahun,$periode_akhir);*/			/*			foreach($get_data_bulan_lalu->result() as $arr_data){				$jml_kredit_bln_lalu[]=$arr_data->KREDIT;			}			$data['total_bulan_lalu']=array_sum($jml_kredit_bln_lalu);*/			$tgl_akhir_bln_lalu=date('Y-m-t',strtotime('-1 month' . $periode_awal));			$tgl_awal_bln_lalu=date('Y-m-d',strtotime('-1 month first day' . $periode_awal));			$data['results'] = $this->laporan_realisasi->getItem_all($periode_awal,$periode_akhir,$tgl_akhir_bln_lalu,$awal_tahun);
			$this->load->view('laporan_realisasi/view_lap_realisasi_periode', $data);
		}
	}
	
	function report_pdf(){
		$periode_awal = $this->uri->segment('3');
		$periode_akhir = $this->uri->segment('4');
		$data['periode_awal']=$this->fungsi->dateindo3('-',$periode_awal);
		$data['periode_akhir']=$this->fungsi->dateindo3('-',$periode_akhir);		$datenow=date('Y');
		$data['results'] = $this->laporan_realisasi->getItem_periode($periode_awal,$periode_akhir);		$data['get_kas_awal'] = $this->laporan_realisasi->getItem_kas_awal($datenow);
		$data['date_now']=$this->fungsi->dateindo3('-',date('Y-m-d'));
        $html = $this->load->view('laporan_realisasi/pdf_lap_realisasi_periode', $data, true);
        $this->pdf->pdf_create($html, 'laporan_realisasi','letter','landscape');
	}
	
	function report_excel(){
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=rekap_realisasi_periode.xls");
		echo  $this->input->post('rekap_tabel1');
	}
	

}